package com.itheima.health.entity;

import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;

/**
 * 封装返回结果
 */
@Data
@SuperBuilder
public class Result implements Serializable {

    @Builder.Default
    private boolean flag = true; // 执行结果，true为执行成功 false为执行失败
    private String message; // 返回结果信息，主要用于页面提示信息
    private Object data; // 返回数据

    public Result(boolean flag, String message) {
        this.flag = flag;
        this.message = message;
    }

    public Result(boolean flag, String message, Object data) {
        this.flag = flag;
        this.message = message;
        this.data = data;
    }

    public static Result success() {
        return Result.builder().flag(true).message("操作成功").build();
    }

    public static Result success(Object data) {
        return Result.builder().flag(true).message("操作成功").data(data).build();
    }

    public static Result success(String message, Object data) {
        return Result.builder().flag(true).message(message).data(data).build();
    }

    public static Result failure() {
        return Result.builder().flag(false).message("操作失败").build();
    }

    public static Result failure(String message) {
        return Result.builder().flag(false).message(message).build();
    }

    public static Result failure(String message, Object data) {
        return Result.builder().flag(false).message(message).data(data).build();
    }

    public static Result error(Object uploadFailed) {
        return null;
    }
}
